package com.javakc.pms.dispord.controller;

import com.javakc.commonutils.api.APICODE;
import com.javakc.pms.dispord.entity.DispOrd;
import com.javakc.pms.dispord.service.DispOrdService;
import com.javakc.pms.dispord.vo.DispOrdQuery;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.repository.query.Param;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 描述：
 */
@Api(tags = "调度指令库管理")
@RestController
@RequestMapping("/pms/dispord")
public class DispOrdController {

    @Autowired
    private DispOrdService dispOrdService;

    @ApiOperation(value = "默认查询所有数据")
    @GetMapping
    public APICODE findAllDispord() {
        List<DispOrd> list = dispOrdService.findAllDispord();
        return APICODE.OK().data("liat", list);
    }

    @ApiOperation(value = "分页带条件查询")
    @PostMapping("{pageNo}/{pageSize}")
    public APICODE queryByPage(@ApiParam(name = "pageNo", value = "页码", required = true)
                               @PathVariable(name = "pageNo") Integer pageNo,
                               @ApiParam(name = "pageSize", value = "最大页数", required = true)
                               @PathVariable(name = "pageSize") Integer pageSize,
                               @ApiParam(name = "dispOrdQuery", value = "条件查询封装类", required = false)
                               @RequestBody(required = false) DispOrdQuery dispOrdQuery) {
        Page<DispOrd> dispOrds = dispOrdService.queryByPage(pageNo, pageSize, dispOrdQuery);
        List<DispOrd> content = dispOrds.getContent();
        long totalElements = dispOrds.getTotalElements();
        return APICODE.OK().data("total", totalElements).data("items", content);
    }

    @ApiOperation("新增方法")
    @PostMapping("insertMethod")
    public APICODE insertMethod(
            @ApiParam(name = "dispOrd",value = "新增数据的封装类")
            @RequestBody DispOrd dispOrd){
        dispOrdService.saveOrUpdate(dispOrd);
        return APICODE.OK();
    }

    @ApiOperation("修改方法")
    @PutMapping("update")
    public APICODE update(
            @ApiParam(name = "dispOrd",value = "新增数据的封装类")
            @RequestBody DispOrd dispOrd){
        dispOrdService.saveOrUpdate(dispOrd);
        return APICODE.OK();
    }

    @ApiOperation("根据id查找")
    @GetMapping("getById/{id}")
    public APICODE getById(
            @ApiParam(name = "id",value = "需要查找的id")
            @PathVariable int id){
        DispOrd byId = dispOrdService.getById(id);
        return APICODE.OK().data("result",byId);
    }

    @ApiOperation("根据id删除")
    @DeleteMapping("deleteById/{id}")
    public APICODE deleteById(
            @ApiParam(name = "id",value = "需要删除的id")
            @PathVariable int id){
        dispOrdService.removeById(id);
        return APICODE.OK();
    }

/**
 * 可用操作符
 * = 等值、!= 不等值 (字符串、数字)
 * >=、<=、>、< (数字)
 * ge，le，gt，lt(字符串)
 * :表示like %v%
 * l:表示 v%
 * :l表示 %v
 * null表示 is null
 * !null表示 is not null
 */
}
